package cn.lijiguo.concurrency.part1.uncaughtexception;

/**
 * UseOwnUnCaughtExceptionHandler
 * 使用自定义 UNCaughtExceptionHandler
 * @author lijiguo
 * @date 2020/1/7 16:34
 */
public class UseOwnUnCaughtExceptionHandler implements Runnable {

    public static void main(String[] args) throws InterruptedException {

        // 设置线程的全局异常处理器
        Thread.setDefaultUncaughtExceptionHandler(new MyUnCaughtExceptionHandler("捕获器1"));

        new Thread(new UseOwnUnCaughtExceptionHandler(), "t1").start();
        Thread.sleep(300);
        new Thread(new UseOwnUnCaughtExceptionHandler(), "t2").start();
        Thread.sleep(300);
        new Thread(new UseOwnUnCaughtExceptionHandler(), "t3").start();
        Thread.sleep(300);
        new Thread(new UseOwnUnCaughtExceptionHandler(), "t4").start();
    }

    @Override
    public void run() {
        throw new RuntimeException("子线程抛出异常");
    }
}
